package com.visikard.asynctask;

import android.os.Handler;
import android.os.Message;

import com.visikard.application.UIMessage;
import com.visikard.business.TransactionHistoryBUS;
import com.visikard.response.BaseResponse;
import com.visikard.response.TransactionHistoryResponse;

public class GetTransactionHistoryCouponTask extends BaseTask {

	public static final int POS_UID = 0;
	public static final int POS_IS_STAFF = 1;
	public static final int POS_STARTDATE = 2;
	public static final int POS_ENDDATE = 3;
	public static final int POS_PAGE_INDEX = 4;
	public static final int POS_PAGE_SIZE = 5;

	public GetTransactionHistoryCouponTask(Handler handler) {
		super(handler);
	}

	public GetTransactionHistoryCouponTask(Handler handler, boolean isShowProgress) {
		super(handler, isShowProgress);
	}

	@Override
	protected Object doBackgroundWork(Object... params) {

		// Get params
		long uid = (Long) params[POS_UID];
		String isStaff = (String) params[POS_IS_STAFF];
		String startDate = (String) params[POS_STARTDATE];
		String endDate = (String) params[POS_ENDDATE];
		int pageIndex = (Integer) params[POS_PAGE_INDEX];
		int pageSize = (Integer) params[POS_PAGE_SIZE];

		// Validation

		// Call service
		TransactionHistoryBUS busObj = new TransactionHistoryBUS();
		return busObj.getTransactionHistoryCouponKardByDate(uid, isStaff, startDate, endDate, pageIndex, pageSize);
	}

	@Override
	protected boolean handleResult(Object result) {
		TransactionHistoryResponse response = (TransactionHistoryResponse) result;
		if (response != null) {
			switch (response.getErrorCode()) {
				case BaseResponse.SUCCESS:
					Message successMsg = new Message();
					successMsg.what = UIMessage.MSG_GET_LIST_SUCCESS;
					successMsg.obj = response.getListTransactionGiftKards();
					mUIHandler.sendMessage(successMsg);
					return true;
			}
		}
		return false;
	}

}
